<?php

class @@beanShortType@@Jsonizer {
    function toPhp($arg0, $helper) {
        if ($arg0 === null) {
            return null;
        }
        
        $ref = ObjectJsonizer::toJsonString($arg0);
        
        $toReturn = $helper->getObject($ref);
        
        if ($toReturn === null) {
            $json = $helper->getJson($ref);
            
            if (false == array_key_exists('__jsonclass__', $json)) {
                throw new Exception('__jsonclass__ is not defined');
            }
            # assume we received a valid object
            
            $jsonclass = $json['__jsonclass__'];
            if ($jsonclass != '@@beanType@@') {
                throw new Exception("expected @@beanType@@, actual $jsonclass");
            }
            # assume the object is of the proper class type
            
            $toReturn = new @@beanShortType@@();
            $helper->putObject($ref, $toReturn);
            
            @@beanSetters@@
        }
        
        return $toReturn;
    }

    function toJson($arg0, $helper) {
        if ($arg0 === null) {
            return null;
        }
        
        if (false == ($arg0 instanceof @@beanShortType@@)) {
            throw new Exception('expected @@beanType@@');
        }
        
        $ref = $helper->fetchRef($arg0);
        if ($ref === null) {
            $ref = $helper->createRef($arg0);
            
            $jsonObject = array();
            $jsonObject['__jsonclass__'] = '@@beanType@@';
            
            @@beanGetters@@
            
            $helper->putJson($ref, $jsonObject);
        }
        
        return $ref;
    }
    
    function toPhpArray($arg0, $helper) {
        if ($arg0 === null) {
            return null;
        }
        
        $toReturn = array();
        foreach ($arg0 as $jsonObject) {
            $toReturn[] = @@beanShortType@@Jsonizer::toPhp($jsonObject, $helper);
        }
        
        return $toReturn;
    }

    function toJsonArray($arg0, $helper) {
        if ($arg0 === null) {
            return null;
        }
        
        $toReturn = array();
        foreach ($arg0 as $phpObject) {
            $toReturn[] = @@beanShortType@@Jsonizer::toJson($phpObject, $helper);
        }
        
        return $toReturn;
    }
    
    function toPhpMap($arg0, $helper) {
        if ($arg0 === null) {
            return null;
        }
        
        $toReturn = array();
        foreach ($arg0 as $jsonKey => $jsonObject) {
            $phpKey = ObjectArrayJsonizer::toPhpString($jsonKey);
            $phpObject = @@beanShortType@@Jsonizer::toPhp($jsonObject, $helper);
            
            $toReturn[$phpKey] = $phpObject;
        }
        
        return $toReturn;
    }

    function toJsonMap($arg0, $helper) {
        if ($arg0 === null) {
            return null;
        }
        
        $toReturn = array();
        foreach ($arg0 as $phpKey => $phpObject) {
            $jsonKey = ObjectArrayJsonizer::toJsonString($phpKey);
            $jsonObject = QuuxJsonizer::toJson($phpObject, $helper);
            
            $toReturn[$jsonKey] = $jsonObject;
        }
        
        return $toReturn;
    }
}

?>